// 引入模块
const express = require("express");
const bodyParser = require("body-parser");
const userRouter = require("./router/user.js");
const commodityRouter = require("./router/commodity");
const congeeRouter =require("./router/congee")
const cors =require("cors");
var cookieParser = require('cookie-parser');

const app = express();
app.listen(3000, () => {
  console.log("running is server...");
});
app.use(cookieParser());
// const session = require("express-session");

// const session = require("express-session");

//解决跨域
app.use(
  cors({
    origin:['http://localhost:8080',"http://127.0.0.1:8080"], credentials:true

  })
);

// 防止默认的报错
app.use(
  bodyParser.urlencoded({
    extended: true,
  })
);

const session = require("express-session");
app.use(session({
    name: 'session-id',
    secret: '123456-78901',
    saveUninitialized: true,
    resave: false
  //   cookie: {
  //     maxAge: 1000 * 60 * 10, // 设置 session 的有效时间，单位毫秒
  // },
}))

//静态资源托管public
app.use(express.static('public'));

// 用户接口
app.use("/user", userRouter);
// 商品模块
app.use("/commodity", commodityRouter);
// 粥谱接口
app.use("/congee", congeeRouter);
